package jmine.tec.web.wicket.component;

import java.net.URL;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.Panel;

/**
 * AjaxLink que gera modalPanel para poder adicionar em outros lugares
 * 
 * @author nara.ribeiro
 * @date Jan 23, 2012
 */
public class InlinedImageLink extends Panel {

    /**
     * Construtor
     * 
     * @param id id
     * @param image image
     * @param modalWindow modalWindow
     * @param panel panel
     */
    public InlinedImageLink(String id, ResourceReference image, final ModalWindow modalWindow, final Panel panel) {
        super(id);

        AjaxLink<Panel> link = new AjaxLink<Panel>("link") {

            @Override
            public void onClick(AjaxRequestTarget target) {
                modalWindow.setContent(panel);
                modalWindow.show(target);
            }
        };
        link.add(new Image("image", image));

        this.add(link);
    }

    /**
     * Construtor
     * 
     * @param id id
     * @param image image
     * @param url url
     */
    public InlinedImageLink(String id, ResourceReference image, URL url) {
        super(id);

        ExternalLink link = new ExternalLink("link", url.toString());
        link.add(new Image("image", image));

        this.add(link);
    }
    
    /**
     * Construtor
     * 
     * @param id id
     * @param image image
     */
    public InlinedImageLink(String id, ResourceReference image) {
        super(id);

        ExternalLink link = new ExternalLink("link", "");
        link.add(new Image("image", image));

        this.add(link.setEnabled(false));
    }
}
